package com.feiyu.aop;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * 连接点
 */
@Slf4j
@Aspect
@Component
public class MyAspect3 {

    @Pointcut("@annotation(com.feiyu.aop.MyLog)")
    public  void pt(){}

    @Before("pt()")
    public  void  before(JoinPoint joinPoint){

        //获取对象名
        String name = joinPoint.getTarget().getClass().getName();
        log.info(name);


        //获取方法名
        String methodName = joinPoint.getSignature().getName();
        log.info(methodName);



        //获取方法执行时需要的参数
        Object[] args = joinPoint.getArgs();
        log.info("目标方法参数：{}", Arrays.toString(args));

        log.info("MyAspect2-MyLog-before");
    }


}
